package ctype

import (
	"database/sql/driver"
	"strings"
)

type Array []string

// 从数据库取数据
func (a *Array) Scan(value interface{}) error {
	bytes := value.([]byte)
	if string(bytes) == "" {
		*a = []string{}
		return nil
	}
	*a = strings.Split(string(bytes), "\n")
	return nil
}

// 保存到数据库
func (a Array) Value() (driver.Value, error) {
	return strings.Join(a, "\n"), nil
}
